package com.cheng.cms.controller;

import com.cheng.cms.domain.Parking;
import com.cheng.cms.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ParkingController {

    @Autowired
    ParkingService parkingService;

    /**
     * 查询所有停车位信息
     * @return
     */
    @GetMapping("/queryInfo/parkingSpaceInfo")
    public String parkingSpaceInf(ModelMap modelMap){
        List<Parking> parkingList = parkingService.selectAllParking();
        modelMap.put("parkingInfo",parkingList);
        return "queryInfo/parkingSpaceInfo";
    }

    /**
     * 根据楼号房号查询所有停车位信息
     * @param buildingNo
     * @param roomNo
     * @return
     */
    @GetMapping("/queryInfo/parkingSpaceInfo/condition")
    @ResponseBody
    public List<Parking> parkingSpaceInfByCondition(String buildingNo,String roomNo){
        Map<String, String> parkingMap = new HashMap<>();
        if(!buildingNo.equals("全部")){
            parkingMap.put("buildingNo",buildingNo);
        }
        if(!roomNo.equals("全部")){
            parkingMap.put("roomNo",roomNo);
        }
        return parkingService.selectAllParkingByCondition(parkingMap);
    }
}
